<template>
	<el-container>
		<el-header>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.remark" placeholder="备注" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="pr_id" @selection-change="selectionChange" hidePagination :params="search">
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="ID" prop="file_id" width="50"></el-table-column>
				<el-table-column label="操作类型" prop="operate_type_name" width="150"></el-table-column>
				<el-table-column label="文件类型" prop="file_type_name" width="150"></el-table-column>
				<el-table-column label="备注" prop="remark" width="150"></el-table-column>
				<el-table-column label="操作人" prop="created_by" width="150"></el-table-column>
				<el-table-column label="创建时间" prop="created_at" width="150"></el-table-column>
				<el-table-column label="开始时间" prop="start_at" width="150"></el-table-column>
				<el-table-column label="结束时间" prop="end_at" width="150"></el-table-column>
				<el-table-column label="结果" prop="result" width="150"></el-table-column>
				<el-table-column label="状态" prop="status_name" width="150"></el-table-column>
				<el-table-column label="最后下载时间" prop="last_download_at" min-width="150"></el-table-column>
				<el-table-column label="下载次数" prop="download_times" min-width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="120">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="download(scope.row, scope.$index)">下载</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
</template>

<script>

export default {
	name: 'rule',
	components: {
	},
	data() {
		return {
			typeList:[],
			dialog: {
				save: false
			},
			apiObj: this.$API['common'].export.list,
			selection: [],
			search: {
				keyword: null,
			}
		}
	},
	mounted() {
	},
	methods: {
		//表格选择后回调事件
		selectionChange(selection){
			this.selection = selection;
		},
		//本地更新数据
		handleSaveSuccess(data, mode){
			if(mode=='add'){
				this.dialog.save = false
				this.$refs.table.refresh()
			}else if(mode=='edit'){
				this.dialog.save = false;
				this.$refs.table.refresh()
			}
			this.$refs.table.refresh()
		},
		//添加
		add() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			});
		},
		//本地更新数据
		handleListSuccess(data, mode) {
			if (mode == 'add') {
				data.id = new Date().getTime()
			} else if (mode == 'edit') {
				this.$refs.table.tableData.filter(item => item.id === data.id).forEach(item => {
					Object.assign(item, data)
				})
			}
			this.$refs.table.refresh()
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		async download(row){
			this.$API['common'].export.download.post({
				file_id: row.file_id,
			}).then(res => {
				if (res.code === 0) {
					this.visible = false;
					this.$message.success("操作成功")
					if (res.data.is_download) {
						window.open(res.data.jump_url);
					} else {
						this.$router.push('/exportFile');
					}
				} else {
					this.$alert(res.msg, "提示", {type: 'error'})
				}
			}).catch(res => {
				this.$alert(res, "提示", {type: 'error'})
			}).finally(() => {
				this.isSaveing = false
			});
		}
	}
}
</script>

<style>
</style>
